// const dbutils = require('./dbutils');  // es5

import { createConnection } from "./dbutils.js"  // 修改为es6

function queryInfoList(success) {
  let querySql = "SELECT  \
	lsc_id \
	, CONCAT('device', SUBSTR(device_id , 17,  4)) AS device_name \
	, mete_id \
	, mete_kind \
	, mete_value \
	, last_mete_value \
	FROM cloud_computing_demo.t_his_telemeterdata \
	LIMIT 100;";
  let connection = createConnection();
  connection.connect();
  connection.query(querySql, (err, res) => {
    if (err == null) {
      success(res);
    } else {
      throw new Error(err);
    }
  });
  connection.end();
}

// 添加 传递参数
function insertStudent(sunNum, stuName, stuClass, age, success) {

  success({ sunNum, stuName, stuClass, age });
  return;

  let insertSql = 'insert into student (sunNum, stuName, stuClass, age) values (?, ?, ?, ?);';
  let connection = dbutils.createConnection();
  let params = [sunNum, stuName, stuClass, age];
  connection.connect();
  connection.query(insertSql, params, (err, res) => {
    if (err == null) {
      console.log(res);
      success(res);
    } else {
      throw new Error(err);
    }
  });
  connection.end();
}

/**
 * 修改为 es6
 */
export {
  queryInfoList,
  insertStudent
};